package com.ruoyi.finance.service.impl;

import com.ruoyi.finance.domain.vo.StatisticsVo;
import com.ruoyi.finance.mapper.StatisticsMapper;
import com.ruoyi.finance.service.IStatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
public class IStatisticsServiceImpl implements IStatisticsService {

    @Resource
    private StatisticsMapper statisticsMapper;
    @Override
    public StatisticsVo getStatisticsByYear(String beginTime,String endTime) {
        StatisticsVo statisticsVo = new StatisticsVo();
        //查 应付
        List<StatisticsVo> statisticsByYear = statisticsMapper.getPayable(beginTime,endTime);
        //查 应收
        List<StatisticsVo> incomeAmount = statisticsMapper.getReceivable(beginTime,endTime);
        //标识集合
        ArrayList<String> nameList = new ArrayList<>();
        //收入额集合
        ArrayList<BigDecimal> sell = new ArrayList<>();
        //支出额集合
        ArrayList<BigDecimal> income = new ArrayList<>();

        //将支出额塞进集合
        statisticsByYear.forEach(sta -> {
            nameList.add(sta.getName());
            income.add(sta.getAmount());
        });

        //将收入塞进集合
        incomeAmount.forEach(i -> {
            sell.add(i.getAmount());
        });


        statisticsVo.setNameList(nameList);
        statisticsVo.setIncomeAmountList(income);
        statisticsVo.setSellAmountList(sell);
        return  statisticsVo;
    }

    @Override
    public StatisticsVo getStatisticsByMonth(String beginTime, String endTime) {

        StatisticsVo statisticsVo = new StatisticsVo();
        //查 应付
        List<StatisticsVo> statisticsByYear = statisticsMapper.getPayableByEndMonth(beginTime,endTime);
        //查 应收
        List<StatisticsVo> incomeAmount = statisticsMapper.getReceivableByBeginMonth(beginTime,endTime);

        //标识集合
        ArrayList<String> nameList = new ArrayList<>();
        //收入额集合
        ArrayList<BigDecimal> sell = new ArrayList<>();
        //支出额集合
        ArrayList<BigDecimal> income = new ArrayList<>();

        //将支出额塞进集合
        statisticsByYear.forEach(sta -> {
            nameList.add(sta.getName());
            income.add(sta.getAmount());
        });

        //将收入塞进集合
        incomeAmount.forEach(i -> {
            sell.add(i.getAmount());
        });


        statisticsVo.setNameList(nameList);
        statisticsVo.setIncomeAmountList(income);
        statisticsVo.setSellAmountList(sell);
        return statisticsVo;
    }

    @Override
    public StatisticsVo getStatisticsByDay(String beginTime, String endTime) {
        StatisticsVo statisticsVo = new StatisticsVo();
        //查 应付
        List<StatisticsVo> statisticsByYear = statisticsMapper.getReceivableByBeginDay(beginTime,endTime);
        //查 应收
        List<StatisticsVo> incomeAmount = statisticsMapper.getPayableByBeginDay(beginTime,endTime);

        //标识集合
        ArrayList<String> nameList = new ArrayList<>();
        //收入额集合
        ArrayList<BigDecimal> sell = new ArrayList<>();
        //支出额集合
        ArrayList<BigDecimal> income = new ArrayList<>();

        //将支出额塞进集合
        statisticsByYear.forEach(sta -> {
            nameList.add(sta.getName());
            income.add(sta.getAmount());
        });

        //将收入塞进集合
        incomeAmount.forEach(i -> {
            sell.add(i.getAmount());
        });


        statisticsVo.setNameList(nameList);
        statisticsVo.setIncomeAmountList(income);
        statisticsVo.setSellAmountList(sell);
        return statisticsVo;
    }
}
